package com.ruoyi.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.system.domain.vo.ArchiveLocationVo;
import com.ruoyi.system.domain.bo.ArchiveLocationBo;
import com.ruoyi.system.service.IArchiveLocationService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 归档位置控制器
 * 前端访问路由地址为:/system/archive_location
 *
 * @author admin
 * @date 2024-12-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/archive_location")
public class ArchiveLocationController extends BaseController {

    private final IArchiveLocationService iArchiveLocationService;

    /**
     * 查询归档位置列表
     */
    @SaCheckPermission("system:archive_location:list")
    @GetMapping("/list")
    public TableDataInfo<ArchiveLocationVo> list(ArchiveLocationBo bo, PageQuery pageQuery) {
        return iArchiveLocationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出归档位置列表
     */
    @SaCheckPermission("system:archive_location:export")
    @Log(title = "归档位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArchiveLocationBo bo, HttpServletResponse response) {
        List<ArchiveLocationVo> list = iArchiveLocationService.queryList(bo);
        ExcelUtil.exportExcel(list, "归档位置", ArchiveLocationVo.class, response);
    }

    /**
     * 获取归档位置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:archive_location:query")
    @GetMapping("/{id}")
    public R<ArchiveLocationVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iArchiveLocationService.queryById(id));
    }

    /**
     * 新增归档位置
     */
    @SaCheckPermission("system:archive_location:add")
    @Log(title = "归档位置", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArchiveLocationBo bo) {
        return toAjax(iArchiveLocationService.insertByBo(bo));
    }

    /**
     * 修改归档位置
     */
    @SaCheckPermission("system:archive_location:edit")
    @Log(title = "归档位置", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArchiveLocationBo bo) {
        return toAjax(iArchiveLocationService.updateByBo(bo));
    }

    /**
     * 删除归档位置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:archive_location:remove")
    @Log(title = "归档位置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iArchiveLocationService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    @Log(title = "归档位置", businessType = BusinessType.UPDATE)
    @PostMapping("/check")
    public R<Void> check(@RequestBody ArchiveLocationBo bo) {
        return toAjax(iArchiveLocationService.checkLoaction(bo));
    }
}
